package com.asp.service.impl;

import com.asp.entity.Practice;
import com.asp.mapper.PracticeMapper;
import com.asp.model.MyPractice;
import com.asp.model.PracticeDetial;
import com.asp.service.PracticeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class PracticeServiceImpl implements PracticeService {

    @Resource
    private PracticeMapper practiceMapper;


    @Override
    public List<MyPractice> selectPractice() {
        List<Practice> practice = practiceMapper.selectPractice();
        List<MyPractice> myPractice = new ArrayList<>();
        for (int i = 0; i < practice.size(); i++) {
            Practice a = practice.get(i);
            ;
            MyPractice b = new MyPractice();
            b.setId(a.getId());
            b.setName(a.getName());
            b.setTitle(a.getTitle());
            b.setImgUrl(a.getImgUrl());
            myPractice.add(b);
        }
        return myPractice;
    }

    @Override
    public List<PracticeDetial> selectDetialById(Integer id) {
        List<Practice> practice = practiceMapper.selectDetialById(id);
        List<PracticeDetial> practiceDetial = new ArrayList<>();
        for (int i = 0; i < practice.size(); i++) {
            Practice a = practice.get(i);
            ;
            PracticeDetial b = new PracticeDetial();
            b.setTest_detialId(a.getTestDetitalid());
            b.setTitle(a.getTitle());
            b.setContent(a.getContent());
            practiceDetial.add(b);
        }
        return practiceDetial;
    }

}